Skip to content

fix(ci): bound source cache snapshots so PR bursts cannot fill main's claim - #5542

Merged
shepherdjerred merged 3 commits into
mainfrom
ci-source-cache-admission
Dec 3, 2026
Merged

shepherdjerred merged 3 commits into
mainfrom
ci-source-cache-admission

Conversation

@shepherdjerred

@shepherdjerred shepherdjerred commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Why

Main went red at ce8aa95 (#20941 and #20949): prepare-clone in helm-push, scout-site-archives and trmnl-plugin-archives failed with

▶  chown 1000:1000 . /woodpecker/source-cache /woodpecker/source-control
chown: /woodpecker/source-cache: Disk quota exceeded

The cache is keyed per commit, and every miss publishes a complete depth-one object store: 1,247,308,780 bytes, or 1.165 GiB on disk. ZFS charges each block clone to the 20 GiB claim in full. The Temporal collector runs every five minutes and keeps 8 GiB, which is six snapshots. Nothing bounded what a burst could add between two runs. Since #5378, owner pull requests publish into woodpecker-source-main. Between 03:35 and 03:40 UTC, 19 distinct owner-PR and main commits started. Twelve snapshots landed on top of the six retained, 18 × 1.165 GiB = 20.97 GiB, and from then on every checkout on the claim failed, hits included, until the 03:40 collection removed 12. The chown is not recursive. It fails because ZFS refuses any write to a dataset that is over its quota.

The Woodpecker 3.21 upgrade (FM-411) is not a factor: the server and all six agents still run v3.20.1.

What

  • src/checkout/admission.ts (new). Before fetching, a miss reserves its snapshot's size in the claim. The reservation is a file published by rename. The snapshot is published only while all published and in-flight snapshots stay under a ceiling of the claim's statfs capacity: 70% for proposals and 85% for main pushes and manual runs. Writers announce before they count, so two concurrent writers may both be refused but can never both overshoot. After the fetch, the reservation is restated with the real size and checked again.
  • snapshot.ts. A refused miss still checks out from its own fetch. It reports published: false in CI_CHECKOUT_DIAGNOSTIC and never touches the cache. A failure at any point removes the reservation.
  • checkout.sh and main.ts. The script hands the helper the locked per-commit descriptor (fd 9). On refusal, the helper unlocks it with flock. The commit's other workflows then fetch in parallel instead of queueing behind a fetch that will never publish.
  • cacheSourceSteps. It emits CI_SOURCE_CACHE_TIER, which is main only for trusted default-branch work. Claims are unchanged. Owner PRs keep sharing woodpecker-source-main. Renovate, App, fork and credentialless builds keep woodpecker-source-pr or no cache, exactly as feat(ci): share main's build cache with owner pull requests #5378 decided. The proposal ceiling sits below main's, so a PR burst cannot take main's last headroom.
  • Killed writers (review P1). Woodpecker cancels superseded workflows with SIGKILL, so a writer killed mid-copy leaves its reservation behind, counted at a full snapshot. The collector (homelab/.../source-cache-gc.ts) holds the GC lock exclusively, and every checkout holds it shared for its whole run, so no writer is ever live while it runs. On each five-minute run it now removes every in-progress copy and any published snapshot missing its manifest, whatever their age, and logs them as abandoned. A dead reservation therefore holds room for at most one collection interval instead of up to seven days.
  • Robustness (review P3).
    • A published snapshot without its manifest counts at full size, with a warning, instead of failing every miss on the claim. The collector removes it, and a hit on it still fails its manifest read.
    • A pipeline emitted without CI_SOURCE_CACHE_TIER publishes under the proposal ceiling, for rollout compatibility. A wrong value still fails. In practice the emitter and helper ship in one image (CI_GATE_IMAGE is the extension's own recipe).
  • commit-lock.ts. The flock release moved out of main.ts so it can be tested.
  • The README and the CI pipeline explanation in the wiki describe the ceiling.

I chose not to resize the claim. A bigger quota only moves the cliff: absorbing this one window (6 + 19 snapshots) would take about 30 GiB, and a longer backlog needs more. I also chose not to route owner PRs back to -pr. That would reverse #5378's choice to keep owner PRs off Renovate-written volumes, and the same burst would then break owner PRs on -pr, where the peak before #5378 was already 11 snapshots per window.

Demo

Live evidence from the source-cache collector, which runs every five minutes. Each run evicts back to six snapshots, so evicted + 6 is the peak since the previous run.

GC run (UTC) main evicted main snapshots before GC main peak GiB on disk pr evicted
02:55 0 6 6.99 0
03:00 4 10 11.65 0
03:25 2 8 9.32 0
03:30 8 14 16.31 0
03:35 7 13 15.14 0
03:40 12 18 20.97 (> 20 Gi) 0
03:45 1 7 8.15 0

The prepare-clone failures were at 03:39:49 UTC. woodpecker-source-pr has had no writes since 2026-11-30, because #5378 took owner PRs off it.

#5378 moved the dominant writer onto main's claim. Snapshots published per five-minute window, from 7 days of collector logs in Loki:

claim period windows with writes p90 max
woodpecker-source-main before #5378 183 2 4
woodpecker-source-main after #5378 153 3.8 12
woodpecker-source-pr before #5378 320 3 11

The incident's 19 commits replayed through the real admission module. The replay starts from the six retained snapshots on a 20 GiB claim, in the order the commits started.

# commit tier before: claim GiB after: decision after: claim GiB
1 fd367e5 proposal 8.13 published 8.13
6 25deeb6 proposal 13.94 published 13.94
7 6e2082e proposal 15.10 refused, fetches unshared 13.94
12 46461ee proposal 20.91 EDQUOT refused, fetches unshared 13.94
14 217bacd proposal 23.23 EDQUOT refused, fetches unshared 13.94
15 ce8aa95 main 24.39 EDQUOT published 15.10
19 908a14d proposal 29.04 EDQUOT refused, fetches unshared 15.10

The claim peaks at 15.10 GiB, under the 17 GiB main ceiling and the 20 GiB quota, and main's own push still publishes. Rows 2 to 5, 8 to 11, 13 and 16 to 18 behave like their neighbors.

statfs reports the ZFS quota (review P2), checked read-only on the live claim.

source value
stat -f /woodpecker/source-main (in pod) 163,840 blocks × 131,072 bytes = 21,474,836,480
df -B1 size 21,474,836,480
PVC woodpecker-source-main 20Gi = 21,474,836,480
ZFSVolume pvc-26793d60… (OpenEBS) capacity: "21474836480", quotaType: "quota", no snapshots (backup off)

zfs get is not reachable without host access. The provisioner sets exactly this quota, so the ceiling's base is the quota itself.

Releasing the commit lock works on Linux in the extension's base image (oven/bun:1.4.5). A second workflow waits on fd 9 while the helper runs:

close=no  waiter acquired after 2503 ms
close=yes waiter acquired after 0 ms

Bun gives a child only the descriptors its stdio array names, so the helper passes fd 9 to flock --unlock 9 at index 9.

Verification

  • bunx turbo run build typecheck test lint --filter=@shepherdjerred/woodpecker-config-extension --filter=@homelab/cdk8s: 40/40 tasks. The extension has 497 passed and 1 skipped (the Linux-only flock test, on macOS); cdk8s has 3194 passed.
  • test/checkout/source-cache-admission.test.ts covers:
    • the ceilings on a 20 GiB claim;
    • 20 concurrent in-process reservations never overshoot;
    • sequential misses stop exactly six above the retained six;
    • main is admitted where proposals are refused;
    • undeclared in-flight copies count in full;
    • a pre-fetch refusal releases the lock once, before the commit's objects arrive, and leaves no snapshot;
    • a post-fetch refusal (admitted on its estimate, over the ceiling at its real size) releases the lock after the fetch;
    • hits need no room.
  • test/checkout/source-cache-writers.test.ts covers:
    • 16 writers in separate processes, started together, never publish past the ceiling;
    • a SIGKILLed writer's reservation persists and counts in full;
    • a restated reservation above the room left withdraws only itself;
    • 200 surveys hold while 200 writers create and withdraw reservations;
    • a manifest-less snapshot counts in full instead of failing;
    • on Linux, the real flock --unlock path frees checkout.sh's descriptor 9 while the helper keeps running. The same protocol was run in oven/bun:1.4.5 against the real fixture: waiter exit 1 while held, 0 after the release.
  • source-cache-gc.test.ts: the collector removes a killed writer's copy and a manifest-less snapshot even when both are fresh and under target, and keeps the rest.
  • test/source-cache.test.ts pins the claim and tier per build shape: main push → main/main; owner PR → main claim with proposal tier; Renovate → pr/proposal.
  • bunx turbo run jscpd quality-ratchet knip --filter=//: pass. bunx lefthook run pre-commit: pass.
  • bun run verify:extended -- --filter='...[origin/main...HEAD]': exit 0, 33/33 tasks, run in @homelab/cdk8s, @shepherdjerred/docs-wiki and @shepherdjerred/woodpecker-config-extension.
  • Not verified: the deployed extension image, the synced collector, and a live burst on woodpecker-source-main.

🤖 Generated with Claude Code

@shepherdjerred

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@greptile-apps

greptile-apps Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository. Configure in Code Review Settings.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@shepherdjerred

Copy link
Copy Markdown
Owner Author

@codex review

Automated re-review request for 0d09284 from the CI review gate.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T04:06:43.221315Z 0d09284 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d09284a10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@shepherdjerred
shepherdjerred force-pushed the ci-source-cache-admission branch 5 times, most recently from 0c8796a to 2c65ffe Compare December 3, 2026 08:42
shepherdjerred and others added 3 commits December 3, 2026 01:34
… claim

Why
Main pipeline #20941 (and #20949) failed in prepare-clone with
"chown: /woodpecker/source-cache: Disk quota exceeded". Every source-cache
miss publishes a complete depth-one object store (1,247,308,780 bytes), and
ZFS charges each block clone to the 20 GiB claim in full. Collection runs
every five minutes and keeps 8 GiB (six snapshots), so nothing bounded what
a burst adds between two runs. Since #5378, owner pull requests publish into
woodpecker-source-main; before it, main never wrote more than 4 snapshots
in a window. Between 03:35 and 03:40 UTC on 2026-12-03, 19 distinct
owner-PR and main commits started, 12 snapshots landed on top of the six
retained (18 x 1.165 GiB = 20.97 GiB on disk), and every checkout on the
claim, hits included, failed until the 03:40 collection removed 12.

What
- src/checkout/admission.ts: a miss reserves its snapshot's size in the
  claim (a reservation file published by rename) before fetching, and
  publishes only while all published and in-flight snapshots stay under a
  ceiling of the claim's statfs capacity: 70% for proposals, 85% for main
  pushes and manual runs. Writers announce before they count, so concurrent
  writers can both be refused but never both overshoot. Reservations are
  restated with the real size after the fetch and checked again.
- snapshot.ts: a refused miss still checks out from its own fetch, reports
  published=false in CI_CHECKOUT_DIAGNOSTIC, never touches the cache, and
  removes its reservation on any failure.
- checkout.sh hands the helper the locked commit descriptor; on refusal the
  helper unlocks it with flock, so the commit's other workflows fetch in
  parallel instead of queueing behind an unpublished fetch.
- cacheSourceSteps emits CI_SOURCE_CACHE_TIER: main only for trusted
  default-branch work. Claims are unchanged: owner PRs keep sharing
  woodpecker-source-main, and Renovate, App, fork and credentialless builds
  keep woodpecker-source-pr or no cache, exactly as #5378 decided.
- README and the CI pipeline explanation describe the ceiling.

Verification
- bunx turbo run build typecheck test lint
  --filter=@shepherdjerred/woodpecker-config-extension: 9/9 tasks, 492 tests.
- New test/checkout/source-cache-admission.test.ts: ceilings on a 20 GiB
  claim, 20 concurrent reservations never overshoot, sequential misses stop
  at exactly six above the retained six, main admitted where proposals are
  refused, undeclared in-flight copies count in full, a refused miss checks
  out, unlocks once before fetching and leaves no snapshot, an empty cache
  is bounded after its fetch, hits need no room.
- Linux probe in oven/bun:1.4.5 (the extension's base image): a waiter on
  the commit lock acquires it after 0 ms when the helper unlocks fd 9 via
  flock, versus 2503 ms when it holds it.
- Replaying the incident's 19 commits through the module keeps the claim at
  15.10 GiB (ceiling 17 GiB, quota 20 GiB); main's ce8aa95 still publishes.
- bunx turbo run jscpd quality-ratchet knip --filter=//: pass.
- bunx lefthook run pre-commit: pass.
- Not verified: exact-head CI, the deployed extension, and a live burst on
  woodpecker-source-main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Why
Review of the source-cache ceiling found that a writer killed mid-copy
(Woodpecker cancels superseded workflows with SIGKILL) leaves its
reservation behind. The admission survey counts it at a full snapshot, while
the collector sums real bytes and kept it for up to seven days, so about
three cancels would eat main's band and about twelve would block proposal
publication. Two smaller gaps: a published snapshot missing its manifest
failed every miss on the claim, and a pipeline emitted without a tier would
crash the helper.

What
- source-cache-gc.ts: the collector holds the GC lock exclusively, which
  every checkout holds shared for its whole run, so it now removes every
  in-progress copy and any snapshot without a manifest on each five-minute
  run, whatever their age, and reports them as abandoned.
- admission.ts: a published snapshot without a manifest counts at full size
  with a warning instead of failing the survey; the collector removes it.
- commit-lock.ts: the flock-based release of checkout.sh's descriptor 9,
  moved out of main.ts so it can be tested.
- main.ts: a missing CI_SOURCE_CACHE_TIER publishes under the proposal
  ceiling for rollout compatibility; a wrong value still fails.
- Tests: separate-process writers never overshoot together; a SIGKILLed
  writer's reservation persists and counts; the collector removes it; a
  restated reservation above the room left withdraws only itself; surveys
  hold while writers withdraw; lock release happens before the fetch on a
  pre-fetch refusal and after it on a post-fetch refusal; on Linux, the real
  flock release frees descriptor 9 while the helper keeps running.

Verification
- bunx turbo run build typecheck test lint for the extension and
  @homelab/cdk8s: 40/40 tasks; extension 497 passed, 1 skipped (the
  Linux-only flock test on macOS); cdk8s 3194 passed.
- The Linux-only test's protocol, run in oven/bun:1.4.5 with the real
  fixture: waiter exit 1 while held, 0 after the release.
- Live, read-only: statfs on woodpecker-source-main reports 163840 blocks of
  131072 bytes = 21474836480 bytes, the PVC's 20Gi and the ZFSVolume's
  capacity with quotaType "quota".
- bunx turbo run jscpd quality-ratchet knip --filter=//: pass.
- bunx lefthook run pre-commit: pass.
- Not verified: exact-head CI, deployment, and a live burst.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Why
Restacking onto #5556 brought a new emit test that calls cacheSourceSteps
without the `main` input this branch made required, so typecheck failed.

What
- The test now passes `main: true` for its trusted cached steps. #5556's
  assertDeclaredCheckout and this branch's tier and commit-lock setup are both
  kept in checkout/main.ts after resolving the restack conflict.

Verification
- bunx turbo run build typecheck test lint for the extension and
  @homelab/cdk8s: 40/40 tasks; extension 504 passed, 1 skipped (the
  Linux-only flock test on macOS); cdk8s 3194 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shepherdjerred
shepherdjerred force-pushed the ci-source-cache-admission branch from 2c65ffe to 8b88d9e Compare December 3, 2026 09:35
@shepherdjerred
shepherdjerred merged commit 6ca1ac4 into main Dec 3, 2026
13 checks passed
@shepherdjerred
shepherdjerred deleted the ci-source-cache-admission branch December 3, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant